/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.g;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.login.plugin.c.a;
import com.qihoo.gamecenter.sdk.login.plugin.h.d;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.login.c;
import org.json.JSONObject;

public class p {
    private Context a;
    private Handler b = new Handler();
    private a c;

    public void a(Context paramContext, String paramString, a parama) {
        e.a("Login.UseLocalTokenLogin4Social", new Object[] { "LocalTokenLogin Entry! account = ", paramString });
        this.a = paramContext;
        this.c = parama;
        new Thread(new Runnable(paramString) {
            public void run() {
                p.a(p.this, this.a);
            }
        }).start();
    }

    private void a(String paramString) {
        a locala = a.a(this.a);
        if (locala != null) {
            String str1 = locala.b(paramString);
            String str2 = locala.a(paramString);
            String str3 = locala.c(paramString);
            if ((!(TextUtils.isEmpty(str1))) && (!(TextUtils.isEmpty(str3))) && (!(TextUtils.isEmpty(str2)))) {
                d.a(str3);
                d.c(str1);
                Intent localIntent = new Intent();
                localIntent.putExtra("login_type", c.a());
                com.qihoo.gamecenter.sdk.login.plugin.h.n localn = n.a(this.a, localIntent, str1);
                if ((localn != null) && (localn.b != null))
                    try {
                        JSONObject localJSONObject1 = localn.b;
                        int i = localJSONObject1.optInt("errno", -1);
                        if (0 == i) {
                            JSONObject localJSONObject2 = localJSONObject1.optJSONObject("data");
                            if (localJSONObject2 != null) {
                                JSONObject localJSONObject3 = localJSONObject2.getJSONObject("accessinfo");
                                JSONObject localJSONObject4 = new JSONObject(str2);
                                JSONObject localJSONObject5 = localJSONObject4.getJSONObject("data");
                                JSONObject localJSONObject6 = localJSONObject3.getJSONObject("token_info");
                                long l = Long.parseLong(localJSONObject6.getString("expires_in"));
                                if (l >= 7200L) {
                                    if (localJSONObject5.has("expires_in"))
                                        localJSONObject5.remove("expires_in");
                                    localJSONObject5.put("expires_in", l);
                                    if (localJSONObject5.has("user_login_res"))
                                        localJSONObject5.remove("user_login_res");
                                    localJSONObject5.put("user_login_res", localJSONObject1);
                                    a(true, localJSONObject4);
                                    return;
                                }
                            }
                        }
                    } catch (Exception localException) {
                        e.b("Login.UseLocalTokenLogin4Social", "", localException);
                    }
            }
        }
        a(false, null);
    }

    private void a(boolean paramBoolean, JSONObject paramJSONObject) {
        if (null == this.c)
            return;
        this.b.post(new Runnable(paramBoolean, paramJSONObject) {
            public void run() {
                p.a(p.this).a(this.a, this.b);
            }
        });
    }

    public static abstract interface a {
        public abstract void a(boolean paramBoolean, JSONObject paramJSONObject);
    }
}